home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-03 | 11.3 KB | 263 lines | [TEXT/R*ch] |
-
-
- cronX10
-
- Version: 1.0b6
- Date: September 3, 1994
- Written by: Jerry Gatlin at Hill Country Softworks
-
- This program is copyrighted by the author and is not in the public
- domain. I am offering this as freeware though, so you are able to
- freely distribute this as long as this documentation accompanies
- the application. You may freely use this in any non-commercial
- manner. If you wish to use it in any other way, please contact the
- author at:
-
- jerry@hipark.austin.isd.tenet.edu
-
- 4702 Valley Oak Dr.
- Austin, Texas 78731
- 512 458-1739
-
- Let me know how you like it and if it works as described.
-
- —————————————————————————————————————————————————————————————————————
-
- NAME
-
- cronX10 - a X10 controller (CP290) program to be used with Chris
- Johnson's cron utility.
-
-
- DESCRIPTION
-
- This program controls X10 modules to turn on and off appliances,
- lights, thermostats, and anything else that can be controlled by
- X10 devices. This program requires a model CP290 X10 computer
- interface along with the appropriate modules for the devices you
- wish to control. X10 is available through a variety of sources and
- both Radio Shack and Leviton make X10 components. Instead of having
- to run wires to these modules to control them, the X10 protocol
- runs over your existing AC wiring. You just plug in (or wire in)
- the module and go.
-
- cronX10 solves a problem I've had for quite some time. The
- application that came with my X10 light controller (CP290) was
- written in the early days of the Macintosh when only MFS was
- around. I finally got tired having to put everything at the root
- level to run, and since I purchased a PowerMac I decided to write
- the code myself.
-
- I'd been wanting to write a cron application for a while and this
- seemed like a natural one. Since cron has a wonderful interface to
- write an application to, and it already solved the scheduling
- problem for me, I wrote this as a faceless bacground application to
- be launched by cron.
-
- This means that YOU MUST HAVE CRON TO RUN THIS PROGRAM!!!
-
- Cron is a Macintosh version of the unix scheduling utility written
- by Chris Johnson. If you're unfamilar with the concept of cron,
- please download cron and read its documentation before spending
- much time with this documentation. You should be able to find cron
- at most of the Mac archive sites. If you have trouble, try these
- sites:
-
- anonymous ftp to ftp.cc.utexas.edu in the /pub/chrisj directory
- the web page http://gargravarr.cc.utexas.edu/cron/cron.html
- anonymous ftp to ftp.utexas.edu in the /pub/mac/util or
- the web page http://www.utexas.edu/cc/microlib-mac/main.html
-
- This has been tested with cron 1.0d16 which is the current version
- as of August 29, 1994.
-
- As cron requires system 7 to run, this application by default
- also requires system 7. Although the Comm ToolBox is built into
- system 7, if for *any* reason Apple chooses to remove it at a later
- time, this app won't work. It will be nice and report the reason
- for its failure to you though.
-
- Although primarily intended for scheduling lights, etc. at
- predetermined times, you can use Chris Johnson's "Command Line"
- cron debugging aid for immediate, direct control of devices.
- "Command Line" simply puts up a dialog and allows you to send
- commands to cron applications immediately instead of setting up
- cron to execute at the next minute and waiting for the minute to
- roll by.
-
- Many thanks to Chris Johnson for writing cron and providing an
- incredible interface to use when writing cron commands. And Chris,
- thanks for the pointers on pointers and handles along with your
- stringUtil functions, several of which I use in this code.
-
- This program is a fat binary (it runs native on either the PowerMac
- or 68k Macs) and was written using the Metrowerks CodeWarrior C
- Compiler.
-
- —————————————————————————————————————————————————————————————————————
-
- Change history:
-
- version 1.0b2 July 15, 1994
- fixed a bug that hung in an infinite loop if CronX10 was launched by
- double-clicking thru the finder. Also added an error message to the
- log file to reflect this.
-
- version 1.0b3 July 19, 1994
- Rewrote X10 routines to acknowledge ACK and event uploads. As a
- result, we can get rid of the semi-heuristic timer that we were
- using before to determine when we could send another event. I also
- cleaned up the serial routines to include WaitNextEvent and a
- timeout so that send and receive won't hang the system under any
- condition. This includes a new routine that waits (with timeout)
- for all characters to be sent through the serial port before
- exiting.
-
- version 1.0b4 August 29, 1994
- Added undocumented x10 direct commands to provide for:
- fade to off
- relative bright
- as identified by John Marvin and brought to my attention by Dick
- Herring (thanks guys!). In the process I had changed my serial
- routines to be more generic and moved all globals from
- serialRoutines into main.
-
-
- version 1.0b5 August 30, 1994
- Changed ppc optimization so native would run in 34k. This had been
- complied incorrectly so that memory had to be increased to 40k for
- native version to run. Added blank lines between error messages in
- error file. Made function parameters case insensitive.
- Fixed a bad bug that would crash the machine if trying to access
- a serial port that was already open. If port is open it will
- now quit elegantly and write an error message in the log.
-
- version 1.0b6 September 3, 1994
- Added -s argument to set the CP290's time to the Macintosh clock
- Fixed bug that would cause cronX10 to hang if there was a
- continuous stream of characters coming in the serial port. It
- now times out after 15 seconds and reports the problem.
- Added date and time to error log.
-
- —————————————————————————————————————————————————————————————————————
-
- Usage: cronX10 [-s][-l level] [-f function] [-h housecode]
- [-u unit] [-p serialPort]
-
- Purpose: To control X10 lamp and applicance modules thru the CP290
- X10 controller using cron to provide the scheduling service.
-
- Options: -s This option will syncronize the CP290's clock with
- the current Macintosh time. If this option is on
- the command line, all other options except -p are
- ignored. This allows you to periodically set the CP290
- clock to keep it accurate. This is particularly useful
- if you've downloaded timer events to the CP290 via
- another program and you wish to keep its clock accurate.
-
- -l Follow this with a number between 0 and 15 to control
- the level of a lamp (dimming) module. 15 is the brightest.
- If this option is not included, level will default
- to 15 (full bright).
-
- -f Follow this with one of these functions:
-
- on (default)
- turns lamp module to full bright
- or appliance module to on.
- off
- turns lamp or appliance module off.
-
- These commands only work on lamp (dimmable) modules:
-
- dim
- turns lamp module to full bright and then
- dims to level set with -l option.
-
- fadeToOff
- fade any lamp module from its current setting
- to off. This is a nice effect.
-
- relativeBright
- relativeBright does the opposite of fadeToOff-
- sort of... If your lamp module has been faded
- using dim to 0 (this WON'T quite turn your lamp
- all the way off) or if you've dimmed your lamp
- using a mini-controller or Leviton switch
- (which for some reason WILL let you dim to
- off!), then you can use this command with an
- appropriate level to increase the brightness.
- If you use a level of 1, it'll increase the
- brightness by 1/15; a level of 3 will increase
- by a level of 3/15, etc. If you've turned your
- lamp module off using off or fadeToOff, this
- command will turn your module on to full
- bright.*
-
- *************************************************************
- * points to remember about these functions
- - It's not my code making the CP290 act this way with
- dim and relativeBright so don't complain to me. I don't
- like it any more than you do!
- - Although the function names aren't case sensitive,
- it'll just default to on if it doesn't understand your
- function due to misspelling..
- *************************************************************
-
- -h Is used to set the base housecode of the X10 unit
- you wish to control. Base housecodes allowable are
- A through P. Upper or lower case are acceptable.
- Default is housecode A.
-
- -u Is used to set the unit number of the X10 unit you
- wish to control. Unit numbers are 1 through 16.
- Numbers over 16 are set to 16. The default on this
- option is unique. If you leave this option out, you
- will control all of the units on a particular
- housecode. In other words, you can turn on all
- units (lights, etc.) in housecode A by leaving
- all options out.
-
- -p Defines the serial port you wish to send the commands
- out of. This application is Comm ToolBox aware and
- you can use any of the registered Com ToolBox names.
- Most often, unless you've changed it, you'll be able
- to use "Modem Port" or "Printer Port". The default is
- for "Modem Port". If your option is not in the
- list of registered serial devices, an entry is made
- to the X10 Error File listing all available device
- names. Include one of the names from this list (don't
- forget the quotes if it's more than one word) and it
- should work just fine.
-
- —————————————————————————————————————————————————————————————————————
-
- X10 Error File:
-
- In addition to writing to the error file when you've defined a wrong
- serial port name, this application will inform you of a variety of
- errors using this file. It will create this file automatically in
- the cron directory (that's where this app must be put to work
- correctly with cron) and will append errors to it as they occur. If
- you're having trouble getting the X10 to respond, look in this
- file. It'll tell you things like the serial port you've selected is
- in use by another application and other errors. It's a text file
- that's double-clickable by BBEdit. This file will only be created
- when an error occurs. Once created, it will continue to append to
- the error log. You may throw this file away at any time.
-
- —————————————————————————————————————————————————————————————————————
-
- Examples of crontab entries:
-
- 20 8 * * * nobody "cronX10" -l 8 -f dim -u 2 -p "Printer Port"
-
- This will turn on unit 2 in housecode A to a dim setting of 8
- using the printer port for communications at 8:20am on every day
- of every week of every year.
-
- 0 0 * * * nobody "cronX10" -f off -h b // all units off in b
-
- This will turn off every unit in housecode B using the modem port
- for communications at midnight on every day of every week of
- every year.